<?php
/**
 * Created by 张彪.
 * User: 小马出行
 * Date: 2018/4/18
 * Time: 11:34
 */
namespace app\admin\inter_model;
use think\Model;
use think\Db;

class RefundModel extends Model
{
    public function addScale($data)
    {
        return Db::table('inter_refund')->insertGetId($data);
    }

    public function updateRefund($map,$data)
    {
        return Db::table('inter_refund')->where($map)->update($data);
    }

    public function getRefund($map,$field='a.*',$page=1,$limit=10)
    {
        $map['e.order_type'] = 3;
        return Db::connect(config('intercity_db'))->name('refund a')
//            ->join('__REFUND_FEE_SCALE__ b','a.scale_id=b.id','LEFT')
            ->join('__ORDER_COMMON__ c','a.common_id=c.id','LEFT')
            ->join(config('inner_db')['database'].'.xm_user d','a.member_id=d.uid','LEFT')
            ->join(config('inner_db')['database'].'.xm_pay_log e','c.id=e.common_id','LEFT')
            ->where($map)->field($field)->page($page,$limit)->order('a.id desc')->select();
    }

    public function searchRefund($map,$field='*')
    {
        $map['e.order_type'] = 3;
        return Db::connect(config('intercity_db'))->name('refund a')
//            ->join('__REFUND_FEE_SCALE__ b','a.scale_id=b.id','LEFT')
            ->join('__ORDER_COMMON__ c','a.common_id=c.id','LEFT')
            ->join(config('inner_db')['database'].'.xm_user d','a.member_id=d.uid','LEFT')
            ->join(config('inner_db')['database'].'.xm_pay_log e','c.id=e.common_id','LEFT')
            ->where($map)->field($field)->order('a.id desc')->find();
    }

    public function getRefundCount($map=array())
    {
        $map['e.order_type'] = 3;
        return Db::connect(config('intercity_db'))->name('refund a')
//            ->join('__REFUND_FEE_SCALE__ b','a.scale_id=b.id','LEFT')
            ->join('__ORDER_COMMON__ c','a.common_id=c.id','LEFT')
            ->join(config('inner_db')['database'].'.xm_user d','a.member_id=d.uid','LEFT')
            ->join(config('inner_db')['database'].'.xm_pay_log e','c.id=e.common_id','LEFT')
            ->where($map)->count();
    }
}